var temp_name,status=1,type;
$(function(){
	queryClass();
	page.bind();
});
var page = { //页面总变量
	bind:function(){
		$("#search").unbind("click");
		$("#search").bind("click.my",function(){
			temp_name=$("#temp_name").val();
			status=$("#status").val();
			type=$("#type").val();
			queryClass();
		})
		/*$(window.parent.document).find("span[data-href='orderlist.html']").parent().unbind('click.my');
		$(window.parent.document).find("span[data-href='orderlist.html']").parent().bind('click.my',function(){
			reloadData();
		})*/
	},
	edit:function(self){
		var id=$(self).val();
		var text=$(self).text();
		var status=(text=='启用')?1:0;
		$.ajax({
	          type: 'POST',
	          url: "createOrder/updateTemplateById",
	          data: {"id":id,"status":status},
	          success: function(data){
	        	  reloadData();
	          }
		});
	}
}
function reloadData(){
	var table = $('#attendanceClassTable').DataTable();
	table.draw(false);
}
//查询
function queryClass(){
	//避免多次绑定
	$('#attendanceClassTable tbody').unbind("click");
	ajaxUtil.dataTablesAjax("attendanceClassTable",10,"createOrder/getTemplateList",
			{"temp_name":temp_name,"type":type,"status":status},[
			{"data":"temp_name",render:function(data,type,row){
					  if(!data) return '';
					  return row.id+" "+data;
			} },
			{"data":"type",render:function(data,type,row){
				if(data==1){return "订单模版";}
				if(data==2){
					return "流程卡模版";
				}
				if(data==3){
					return "业务单模版";
				}
			}},
			{"data":"status",render:function(data,type,row){
				if(data==0){return "<span style='color:red'>禁用</span>";}else{
					return "<span style='color:green'>启用</span>";
				}
			}},
			{"data":"id",render:function(data,type,row){
				if(row.status==1){
					return "<button id='edit_status'  class='edit-btn btn' onclick='page.edit(this)' type='button' value='"+data+"'>禁用</button>";
				}else{
					return "<button id='edit_status'  class='edit-btn btn' onclick='page.edit(this)' type='button' value='"+data+"'>启用</button>";
				}
			} }
	]);
	$('#attendanceClassTable').on( 'init.dt', function ( e, settings ) {
		layer.msg("查询完成",{icon:1});
	});
	
}

/*
$("iframe[src='./html/createOrder/index_x.html']")[0].contentWindow.basic_index.getTempForOrder('182','SC180308000010')*/




